package com.happyclub.lbjdao;


import com.happyclub.pojo.TbActivity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;


public interface FindHotActivityList extends JpaRepository<TbActivity,String>{
    /**
     * @Author 高欢
     * @Description  先筛选出通过审核平且还未过期的活动
     * @Date 20:33 2019/4/6
     **/
    /*@Query(value = "SELECT ROWNUM ,activity_id from (SELECT ACTIVITY_ID, COUNT(USER_ID) from TB_ACTIVITY_USER where ACTIVITY_ID IN (SELECT ID from TB_ACTIVITY where ACTIVITY_EXPIRED_TIME > SYSDATE and Ok = 1) GROUP BY ACTIVITY_ID) ORDER BY ROWNUM DESC",nativeQuery = true)*/
    List<TbActivity> findTbActivitiesByOkAndActivityEndTimeAfter(long ok, Date date);

    @Query(value = "SELECT ACTIVITY_ID, COUNT(USER_ID) num from TB_ACTIVITY_USER where ACTIVITY_ID IN (SELECT ID from TB_ACTIVITY where ACTIVITY_EXPIRED_TIME > SYSDATE and Ok = 1) GROUP BY ACTIVITY_ID ORDER BY num DESC",nativeQuery = true)
    List<Object[]> getHot();
}
